
<?php

    header('content-type:text/html;charset=utf-8') ;
    header("Access-Control-Allow-Origin:*");


    // 连接数据库需要主机名，端口号，用户名和密码 库名

<<<<<<< HEAD
    $host = 'b-k5hmuwuw4s0vsb.bch.rds.gz.baidubce.com:3306';
    $name = 'b_k5hmuwuw4s0vsb';
    $pwd = 'czm061002';
    $dbname = 'b_k5hmuwuw4s0vsb';
    $conn = mysqli_connect("b-k5hmuwuw4s0vsb.bch.rds.gz.baidubce.com","b_k5hmuwuw4s0vsb","czm061002","b_k5hmuwuw4s0vsb") ;
=======
    // $host = 'localhost:3306' ;
    // $name = 'root' ;
    // $pwd = 'root' ;
    // $dbname = '123' ;

    $conn = mysqli_connect("localhost","root","root","123") ;
>>>>>>> c2a0b16d374b2dadbf60483b2ca7e378d937a164
    if(!$conn) {
        // 结束
        die('数据库连接失败') ;
    } 

    $uname = $_GET['phone'] ;
    $upwd = $_GET['password'] ;

    // $uname = 'yy' ;
    // $upwd = '123' ;


    $obj = [] ;

    if($uname && $upwd) {

        // 去数据库查询用户名是否存在
        // 在php中双引号可以解析变量
        $sql = "SELECT * from user where phone = '$uname' " ;

        // 执行sql语句   得到的是一个表格
        $res = mysqli_query($conn , $sql) ;
        // 把表格变成数组
        $data = mysqli_fetch_array($res) ;
        // var_dump($data) ;
        if($data) {
            // 判断密码
            if($data['password'] === $upwd) {
                $obj['status'] = true ;
                $obj['msg'] = '登录成功';
            } else {
                $obj['status'] = false ;
                $obj['msg'] = '用户名或者密码错误';
            }
        } else {
            $obj['status'] = false ;
            $obj['msg'] = '用户名不存在';
        }

    } else {
        $obj['status'] = false ;
        $obj['msg'] = '前端数据错误';
    }


    echo(json_encode($obj , JSON_UNESCAPED_UNICODE)) ;



